        /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.alternative.ranks;

import data.ACStorage;
import exception.MarkNotInSatScaleException;
import java.util.List;
import logic.Normalizer;
import model.Criteria;

/**
 *
 * @author Djordje Gligorijevic
 */
public class ControllerAlternativeRanks {

    private ControllerAlternativeRanks() {
    }

    public static ControllerAlternativeRanks getInstance() {
        return ControllerAlternativeRanksHolder.INSTANCE;
    }

    private static class ControllerAlternativeRanksHolder {

        private static final ControllerAlternativeRanks INSTANCE = new ControllerAlternativeRanks();
    }

    public void next() {
    }

    public void previous() {
    }

    public void sliderAlternative(int rowIndex, int columnIndex, int sliderValue, int criteriaC) throws MarkNotInSatScaleException {
        if (sliderValue >= 0) {
            ACStorage.getInstance().getGoal().getListCriteria().get(criteriaC).insertMark(
                    ACStorage.getInstance().getGoal().getListAlternative().get(columnIndex - 1),
                    ACStorage.getInstance().getGoal().getListAlternative().get(rowIndex),
                    Math.abs(sliderValue) + 1);
            ACStorage.getInstance().getGoal().getListCriteria().get(criteriaC).insertMark(
                    ACStorage.getInstance().getGoal().getListAlternative().get(rowIndex),
                    ACStorage.getInstance().getGoal().getListAlternative().get(columnIndex - 1),
                    1.0 / (Math.abs(sliderValue) + 1));


        } else {
            ACStorage.getInstance().getGoal().getListCriteria().get(criteriaC).insertMark(
                    ACStorage.getInstance().getGoal().getListAlternative().get(columnIndex - 1),
                    ACStorage.getInstance().getGoal().getListAlternative().get(rowIndex),
                    1.0 / (Math.abs(sliderValue) + 1));
            ACStorage.getInstance().getGoal().getListCriteria().get(criteriaC).insertMark(
                    ACStorage.getInstance().getGoal().getListAlternative().get(rowIndex),
                    ACStorage.getInstance().getGoal().getListAlternative().get(columnIndex - 1),
                    Math.abs(sliderValue) + 1);

        }
    }
    
    public void averageValues(List<Double> averageValues, int criteriaCounter){
    for (int i = 0; i < ACStorage.getInstance().getGoal().getListAlternative().size(); i++) {
            double value = 0;
            for (int k = 0; k < ACStorage.getInstance().getGoal().getListCriteria().get(criteriaCounter).getAllAlternativeRanks().size(); k++) {
                if (ACStorage.getInstance().getGoal().getListCriteria().get(criteriaCounter).getAllAlternativeRanks().get(k).getSecondAlternative().
                        equals(ACStorage.getInstance().getGoal().getListAlternative().get(i))) {
                    value += ACStorage.getInstance().getGoal().getListCriteria().get(criteriaCounter).getAllAlternativeRanks().get(k).getNormalizedMark();
                }
            }
            averageValues.add(value / ACStorage.getInstance().getGoal().getListAlternative().size());
        }
        ACStorage.getInstance().getGoal().getListCriteria().get(criteriaCounter).setAverageValues(averageValues);
    }

    public void normalize(String normalizer, Criteria criteria) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        ((Normalizer) Class.forName("logic." + normalizer).newInstance()).normalize(criteria);
    }
}
